﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MMeller.Net.MultiHashmap
{
    public class MultiHashmap<K,V>
    {
        Dictionary<K, IInternalDict<object, V>> hashmaps;

        public MultiHashmap(List<HashmapType<K>> hashmapTypes)
        {
            this.hashmaps = new Dictionary<K, IInternalDict<object, V>>();

            foreach (HashmapType<K> hashmapType in hashmapTypes)
            {
                if (hashmapType.multiValue)
                {
                    this.hashmaps[hashmapType.name] = (IInternalDict<object, V>)new ExtendedDictionary<object, V>();
                }
                else
                {
                    this.hashmaps[hashmapType.name] = (IInternalDict<object, V>)new SimpleDictionary<object, V>();
                }
            }
        }

        public void loadElement(List<MultiHashmapElement<K,V>> elements)
        {
            if (elements.Count != this.hashmaps.Count)
            {
                throw new Exception("incorrect number of elements");
            }
            else
            {
                foreach (MultiHashmapElement<K,V> element in elements)
                {
                    this.hashmaps[element.HashmapName].Add(element.Key, element.Value);
                }
            }
        }

        public V[] getElement(K hashmapName, object hashmapKey)
        {
            return this.hashmaps[hashmapName].getElement(hashmapKey);
        }

    }
}
